package com.zhouyu.validator;

import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class ValidatorTest implements Validator {
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public static void main(String[] args) {

	}

	@Override
	public boolean supports(Class<?> clazz) {
		return ValidatorTest.class.equals(clazz);
	}

	@Override
	public void validate(Object target, Errors errors) {
		ValidatorTest user = (ValidatorTest) target;
		if (StringUtils.isEmpty(user.getName())) {
			errors.rejectValue("name", "name.required", "Name cannot be empty");
		}
	}
}
